﻿<!DOCTYPE HTML>
<html lang="zh">
<head>
<title>ControlClick - 语法 &amp; 使用 | AutoHotkey v2</title>
<meta name="description" content="The ControlClick function sends a mouse button or mouse wheel event to a control." />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href="../static/theme.css" rel="stylesheet" type="text/css" />
<script src="../static/content.js" type="text/javascript"></script>
<script type="text/javascript">$(function(){0<=window.navigator.userAgent.toLowerCase().indexOf("ucbrowser")&&CaoNiMaDeUc()})</script>
</head>
<body>

<h1>ControlClick</h1>

<p>发送鼠标按钮或鼠标滚轮事件到控件.</p>

<pre class="Syntax"><span class="func">ControlClick</span> <span class="optional">Control-or-Pos, WinTitle, WinText, WhichButton, ClickCount, Options, ExcludeTitle, ExcludeText</span></pre>
<h2 id="Parameters">参数</h2>
<dl>

  <dt>Control-or-Pos</dt>
  <dd>
      <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a>或<a href="../Objects.htm">对象</a></p>
      <p>If this parameter is omitted, the target window itself will be clicked. Otherwise, one of the two modes below will be used.</p>
      <p>Mode 1 (Position): Specify the X and Y coordinates relative to the upper left corner of the target window's <a href="CoordMode.htm#Client">client area</a>. The X coordinate must precede the Y coordinate and there must be at least one space or tab between them. 例如: <code>X55 Y33</code>. If there is a control at the specified coordinates, it will be sent the click-event at those exact coordinates. If there is no control, the target window itself will be sent the event (which might have no effect depending on the nature of the window).</p>
    <p class="note"><strong>Note</strong>: In mode 1, the X and Y option letters of the <em>Options</em> parameter are ignored.</p>      
      <p>Mode 2 (Control): Specify the control's ClassNN, text or HWND, or an object with a <code>Hwnd</code> property. For details, 请参阅 <a href="Control.htm#Parameter">The Control Parameter</a>.</p>
      <p>By default, mode 2 takes precedence over mode 1. 例如, in the unlikely event that there is a control whose text or ClassNN has the format &quot;Xnnn Ynnn&quot;, it would be acted upon by Mode 2. To override this and use mode 1 unconditionally, specify the word Pos in <em>Options</em> as in the following example: <code>ControlClick "x255 y152", WinTitle,,,, "Pos"</code>.</p>
  </dd>

  <dt>WinTitle</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a>, <a href="../Concepts.htm#numbers">整数</a>或<a href="../Objects.htm">对象</a></p>
    <p>识别目标窗口的窗口标题或其他条件. 请参阅 <a href="../misc/WinTitle.htm">WinTitle</a>.</p>
  </dd>

  <dt>WinText</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>如果存在, 此参数必须是目标窗口的单个文本元素的子字符串(和内置的 Window Spy 工具显示的一样). 如果 <a href="DetectHiddenText.htm">DetectHiddenText</a> 为 ON, 那么会检测隐藏文本元素.</p>
  </dd>

  <dt>WhichButton</dt>
  <dd>
      <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
      <p>The button to click: LEFT, RIGHT, MIDDLE (or just the first letter of each of these). If omitted or blank, the LEFT button will be used.</p>
      <p>X1 (XButton1, the 4th mouse button) and X2 (XButton2, the 5th mouse button) are also supported.</p>
      <p>WheelUp (or WU), WheelDown (or WD), WheelLeft (or WL) and WheelRight (or WR) are also supported. In this case, <em>ClickCount</em> is the number of notches to turn the wheel.</p>
    </dd>

  <dt>ClickCount</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#numbers">整数</a></p>
    <p>The number of clicks to send. If omitted or blank, 1 click is sent.</p>
  </dd>

  <dt>Options</dt>
  <dd>
      <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
      <p>A series of zero or more of the following option letters. 例如: d x50 y25</p>
      <p><strong>NA</strong>: May improve reliability. See <a href="#Reliability">reliability</a> below.</p>
      <p><strong>D</strong>: Press the mouse button down but do not release it (i.e. generate a down-event). If both the <strong>D</strong> and <strong>U</strong> options are absent, a complete click (down and up) will be sent.</p>
      <p><strong>U</strong>: Release the mouse button (i.e. generate an up-event). This option should not be present if the <strong>D</strong> option is already present (and vice versa).</p>
      <p><strong>Pos</strong>: Specify the word Pos anywhere in <em>Options</em> to unconditionally use the X/Y positioning mode as described in the <em>Control-or-Pos</em> parameter above.</p>
      <p><strong>Xn</strong>: Specify for <strong>n</strong> the X position to click at, relative to the control's upper left corner. If unspecified, the click will occur at the horizontal-center of the control.</p>
      <p><strong>Yn</strong>: Specify for <strong>n</strong> the Y position to click at, relative to the control's upper left corner. If unspecified, the click will occur at the vertical-center of the control.</p>
      <p>Use decimal (not hexadecimal) numbers for the <strong>X</strong> and <strong>Y</strong> options.</p>
  </dd>

  <dt>ExcludeTitle</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>标题中含有此参数值的窗口将被排除.</p>
  </dd>

  <dt>ExcludeText</dt>
  <dd>
    <p>类型: <a href="../Concepts.htm#strings">字符串</a></p>
    <p>文本中含有此参数值的窗口将被排除.</p>
  </dd>

</dl>

<h2 id="Error_Handling">错误处理</h2>
<p>An exception is thrown in the following cases:</p>
<ul>
  <li>The target window could not be found.</li>
  <li>The target control could not be found and <em>Control-or-Pos</em> does not specify a valid position.</li>
  <li>Very rare: the X or Y position is omitted and the control's position could not be determined.</li>
  <li>Invalid parameters were detected.</li>
</ul>

<h2 id="Reliability">Reliability</h2>
<p>To improve reliability -- especially during times when the user is physically moving the mouse during the ControlClick -- one or both of the following may help:</p>
<p>1) Use <code><a href="SetControlDelay.htm">SetControlDelay</a> -1</code> prior to ControlClick. This avoids holding the mouse button down during the click, which in turn reduces interference from the user's physical movement of the mouse.</p>
<p>2) Specify the string NA anywhere in the sixth parameter (<em>Options</em>) as shown below:</p>
<pre>SetControlDelay -1
ControlClick "Toolbar321", WinTitle,,,, "NA"</pre>
<p><code>NA</code> avoids marking the target window as active and avoids merging its input processing with that of the script, which may prevent physical movement of the mouse from interfering (but usually only when the target window is not active). However, this method might not work for all types of windows and controls.</p>
<h2 id="Remarks">备注</h2>
<p>Not all applications obey a <em>ClickCount</em> higher than 1 for turning the mouse wheel. For those applications, use a Loop to turn the wheel more than one notch as in this example, which turns it 5 notches:</p>
<pre>Loop 5
    ControlClick <i>Control</i>, <i>WinTitle</i>, <i>WinText</i>, "WheelUp"</pre>
<p>窗口标题和文本是区分大小写的. 除非 <a href="DetectHiddenWindows.htm">DetectHiddenWindows</a> 被打开, 否则不会检测隐藏窗口.</p>

<h2 id="Related">相关</h2>
<p><a href="SetControlDelay.htm">SetControlDelay</a>, <a href="Control.htm">Control 函数</a>, <a href="Click.htm">Click</a></p>
<h2 id="Examples">示例</h2>
<div class="ex" id="ExBasic">
<p><a href="#ExBasic">#1</a></p>
<pre>ControlClick "OK", "Some Window Title"  <em>; 点击 OK 按钮</em>
ControlClick "x55 y77", WinTitle  <em>; 在坐标上进行点击. 注意 X 和 Y 之间的空隙.</em></pre>
</div>

<div class="ex" id="ExReliability">
<p><a href="#ExReliability">#2</a>: 下面的方法可以提高可靠性并减少副作用:</p>
<pre>SetControlDelay -1
ControlClick "Toolbar321", WinTitle,,,, "NA x192 y10"  <em>; 使用 NA 模式在相对于命名控件的坐标处进行点击.</em></pre>
</div>

</body>
</html>